package com.rong.template.advice.log;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import cn.hutool.core.util.StrUtil;
import com.rong.template.advice.session.SessionContextHolder;

/**
 * @Description
 * @Author rongyi
 * @Date 2021/4/22
 **/
public class TraceIdConvert  extends ClassicConverter {

    @Override
    public String convert(ILoggingEvent event) {

        String traceId = SessionContextHolder.getContext().getTraceId();

        return StrUtil.isEmpty(traceId)? Thread.currentThread().getName():traceId;
    }
}
